package com.ruoyi.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.base.domain.BaseFruitStock;
import com.ruoyi.base.service.IBaseFruitStockService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 果品库存操作Controller
 * 
 * @author ruoyi
 * @date 2024-01-21
 */
@RestController
@RequestMapping("/base/stock")
public class BaseFruitStockController extends BaseController
{
    @Autowired
    private IBaseFruitStockService baseFruitStockService;

    /**
     * 查询果品库存操作列表
     */
    @PreAuthorize("@ss.hasPermi('base:stock:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseFruitStock baseFruitStock)
    {
        startPage();
        List<BaseFruitStock> list = baseFruitStockService.selectBaseFruitStockList(baseFruitStock);
        return getDataTable(list);
    }

    /**
     * 导出果品库存操作列表
     */
    @PreAuthorize("@ss.hasPermi('base:stock:export')")
    @Log(title = "果品库存操作", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseFruitStock baseFruitStock)
    {
        List<BaseFruitStock> list = baseFruitStockService.selectBaseFruitStockList(baseFruitStock);
        ExcelUtil<BaseFruitStock> util = new ExcelUtil<BaseFruitStock>(BaseFruitStock.class);
        util.exportExcel(response, list, "果品库存操作数据");
    }

    /**
     * 获取果品库存操作详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:stock:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baseFruitStockService.selectBaseFruitStockById(id));
    }

    /**
     * 新增果品库存操作
     */
    @PreAuthorize("@ss.hasPermi('base:stock:add')")
    @Log(title = "果品库存操作", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseFruitStock baseFruitStock)
    {
        return toAjax(baseFruitStockService.insertBaseFruitStock(baseFruitStock));
    }

    /**
     * 修改果品库存操作
     */
    @PreAuthorize("@ss.hasPermi('base:stock:edit')")
    @Log(title = "果品库存操作", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseFruitStock baseFruitStock)
    {
        return toAjax(baseFruitStockService.updateBaseFruitStock(baseFruitStock));
    }

    /**
     * 删除果品库存操作
     */
    @PreAuthorize("@ss.hasPermi('base:stock:remove')")
    @Log(title = "果品库存操作", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseFruitStockService.deleteBaseFruitStockByIds(ids));
    }
}
